****************************************************************************************************************
**																											  **
** This do file is part of the replication material for the following article: 								  **
**  "Is There an Ideological Asymmetry in the Incumbency Effect? Evidence from U.S. Congressional Elections." **
** 		Authors: Morisi, Davide, Jost, John, Panagopoulos, Costas, and Jussi Valtonen		    			  **
** 		Journal: Social Psychological and Personality Science																				  **
**																											  **
** This file replicates the following step of the analysis: 												  **
**																											  **
**		TABLES AND FIGURES INCLUDED IN APPENDIX	A														  	  ** 
**																											  **
****************************************************************************************************************

*Set working directory
cd "C:\Users\Davide Morisi\Dropbox\datasets"

*Open merged dataset
use "CCES\CCES_merged_dataset9.dta", clear

set matsize 800

*Demographics
global demo3 "i.gender birthyr ib2.educ i.racer i.religpewr ib2.economy3"

*Additional controls for House elections
global control_house "i.held_offices2 i.freshman i.redist dexp10 rexp10"
fre held_offices2 freshman redist
fre held_offices2 freshman redist if filter_hou_new==1

*Filter out open seats/seats without 2 major parties in House & Senate
fre filter_hou_new
fre filter_sen1

*Do not use old var for house incumbent & state
rename inc_rep_hou OLD_inc_rep_hou
rename inc_all_hou OLD_inc_all_hou
rename inc_all_hou_filter OLD_inc_all_hou_f
rename own_incLCMpre_hou OLD_own_incLCMpre_hou
rename own_incDRIprof_hou OLD_own_incDRIprof_hou
rename state OLD_state
*New var
rename inc_rep_hou2 inc_rep_hou
rename inc_all_hou2 inc_all_hou
rename own_incLCMpre_hou2 own_incLCMpre_hou
rename own_incDRIprof_hou2 own_incDRIprof_hou
fre inc_all_hou // already filtered
fre inc_rep_hou if filter_hou_new==1

*Districts with alternation
egen mean_rep_inc = mean(inc_rep_hou) if filter_hou_new==1, by(stcd)
fre mean_rep_inc
*ta stcd inc_rep_hou if filter_hou_new==1 & mean_rep_inc==0 // districts with only dem inc
*ta stcd inc_rep_hou if filter_hou_new==1 & mean_rep_inc==1 // districts with only rep inc
ta stcd inc_rep_hou if filter_hou_new==1 & mean_rep_inc>0 & mean_rep_inc<1 // districts with both inc
gen filter_dist = 0 if mean_rep_inc!=.
replace filter_dist = 1 if mean_rep_inc>0 & mean_rep_inc<1
fre filter_dist // 37% districts with alternations

**************************

*
*Table A1. Summary statistics
ta votedemrep_hou, gen(votedemrep_hou_cat)
ta inc_rep_hou, gen(inc_rep_hou_cat)
ta votedemrep_sen, gen(votedemrep_sen_cat)
ta inc_rep_sen, gen(inc_rep_sen_cat)
ta ideo7pre, gen(ideo7pre_cat)
ta pid3prof, gen(pid3prof_cat)
fre gender educ racer religpewr economy
gen female = gender-1
ta educ, gen(educ_cat)
ta racer, gen(race_cat)
ta religpewr, gen(religpewr_cat)
ta economy3, gen(economy3_cat)
fre held_offices2 freshman redist
ta year, gen(year_cat)

*HOUSE
preserve
	keep if filter_hou_new==1 & votedemrep_hou!=.
	*table
	eststo clear
	estpost sum votedemrep_hou_cat* inc_rep_hou_cat* ideo7pre_cat* pid3prof_cat* ///
	female educ_cat* race_cat* religpewr_cat* economy3_cat* ///
	held_offices2 freshman redist year_cat* [iweight=weight1]
	esttab using "~TableA1_house.rtf", cells("count sum_w mean") replace
	sum birthyr dexp10 rexp10 [iweight=weight1]
restore

*SENATE
preserve
	keep if filter_sen1==1 & votedemrep_sen!=.
	*table
	eststo clear
	estpost sum votedemrep_sen_cat* inc_rep_sen_cat* ideo7pre_cat* pid3prof_cat* ///
	female educ_cat* race_cat* religpewr_cat* economy3_cat* ///
	year_cat* [iweight=weight1]
	esttab using "~TableA1_senate.rtf", cells("count sum_w mean") replace
	sum birthyr [iweight=weight1]
restore

drop votedemrep_hou_cat* inc_rep_hou_cat* votedemrep_sen_cat* inc_rep_sen_cat* ///
ideo3pre_cat* pid3prof_cat* ///
female educ_cat* race_cat* religpewr_cat* economy3_cat* year_cat*


*
*Table A2. Vote for congressional candidates by ideology and incumbent status (2006-2018) – House 
eststo clear
*1
eststo: logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou i.stcd i.year if filter_hou_new==1 [pweight=weight1]
*2
eststo: logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
*3 only districts with alternation
eststo: logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 & filter_dist==1 [pweight=weight1]
esttab using "~TableA2_HOUSE_R&R.rtf", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("TableA2. Incumbency effects, logistic regressions, ideology - HOUSE") wide compress noeqlines replace


*
*Table A3. Average marginal effects based on Table A2
eststo clear
*model 1
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_hou==0) post
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_hou==1) post
*model 2
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_hou==0) post
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_hou==1) post
*model 3
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 & filter_dist==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_hou==0) post
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 & filter_dist==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_hou==1) post
*table
esttab using "~TableA3_HOUSE_r&r.rtf", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Average marginal effects based on Table A2 - HOUSE") compress noeqlines replace
*incumbency effect, model 1
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou i.stcd i.year if filter_hou_new==1 [pweight=weight1]
margins ideo2pre, dydx(own_incLCMpre_hou)
margins r.ideo2pre, dydx(own_incLCMpre_hou)
*incumbency effect, model 2
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
margins ideo2pre, dydx(own_incLCMpre_hou)
margins r.ideo2pre, dydx(own_incLCMpre_hou)
*incumbency effect, model 3
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 & filter_dist==1 [pweight=weight1]
margins ideo2pre, dydx(own_incLCMpre_hou)
margins r.ideo2pre, dydx(own_incLCMpre_hou)


*
*SENATE
*Table A4. Incumbency effects as a function respondent ideology in Congressional elections (2008-2018) - SENATE
eststo clear
eststo: logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
esttab using "~TableA4_SENATE.rtf", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("TableA4. Incumbency effects, logistic regressions, ideology - SENATE") wide compress noeqlines replace


*
*Table A5. Average marginal effects based on Table A4 - SENATE
eststo clear
*model 1
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_sen==0) post
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_sen==1) post
*model 2
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_sen==0) post
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_sen==1) post
*table
esttab using "~TableA5_SENATE.rtf", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Average marginal effects based on Table A4 - SENATE") compress noeqlines replace
*incumbency effect, model 1
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen i.staten i.year if filter_sen1==1 [pweight=weight1]
margins ideo2pre, dydx(own_incLCMpre_sen)
margins r.ideo2pre, dydx(own_incLCMpre_sen) // p=0.08
*incumbency effect, model 2
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
margins ideo2pre, dydx(own_incLCMpre_sen)
margins r.ideo2pre, dydx(own_incLCMpre_sen)


*
*Table A6. Incumbency effects, registered voters only
fre register_post
eststo clear
*House - Model 2 in Table A2, registered voters only
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 & register_post==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_hou==0) post
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 & register_post==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_hou==1) post
*Senate - Model 2 in Table A4, registered voters only
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 & register_post==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_sen==0) post
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 & register_post==1 [pweight=weight1]
eststo: margins ideo2pre, at(own_incLCMpre_sen==1) post
esttab using "~TableA6_registered.rtf", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Registered voters only") compress noeqlines replace
*incumbency effect, model 2 HOUSE
eststo clear
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 & register_post==1 [pweight=weight1]
margins ideo2pre, dydx(own_incLCMpre_hou)
margins r.ideo2pre, dydx(own_incLCMpre_hou)
*incumbency effect, model 2 SENATE
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 & register_post==1 [pweight=weight1]
margins ideo2pre, dydx(own_incLCMpre_sen)
margins r.ideo2pre, dydx(own_incLCMpre_sen)


**************
*Figure A1. Incumbency effects as a function of ideological strength (2006-2018)
fre ideo6pre

*HOUSE
*main model
*logit own_candLCMpre_hou i.ideo6pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
*Somewhat liberals/conservatives, lib=.143
eststo clear
logit own_candLCMpre_hou i.ideo6pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo slib: margins 3.ideo6pre, dydx(own_incLCMpre_hou) post 
logit own_candLCMpre_hou i.ideo6pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo scon: margins 5.ideo6pre, dydx(own_incLCMpre_hou) post
coefplot (slib, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(scon, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) yscale(range(0(.02).20)) ylabel(0(.02).20) ///
ytitle("Incumbency effect") title("Weak") legend(off) ///
graphregion(color(white)) name(figure2a, replace)
*liberals/conservatives
logit own_candLCMpre_hou i.ideo6pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo lib: margins 2.ideo6pre, dydx(own_incLCMpre_hou) post 
logit own_candLCMpre_hou i.ideo6pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo con: margins 6.ideo6pre, dydx(own_incLCMpre_hou) post 
coefplot (lib, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(con, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) yscale(range(0(.02).20)) ylabel(0(.02).20) ///
ytitle("") title("Medium") legend(off) ///
graphregion(color(white)) name(figure2b, replace)
*very
logit own_candLCMpre_hou i.ideo6pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo vlib: margins 1.ideo6pre, dydx(own_incLCMpre_hou) post 
logit own_candLCMpre_hou i.ideo6pre##i.own_incLCMpre_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo vcon: margins 7.ideo6pre, dydx(own_incLCMpre_hou) post 
coefplot (vlib, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(vcon, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) yscale(range(0(.02).20)) ylabel(0(.02).20) ///
ytitle("") title("Strong") legend(off) ///
graphregion(color(white)) name(figure2c, replace)
*COMBINED
graph combine figure2a figure2b figure2c, title("House") graphregion(color(white)) name(house_comb)


*SENATE
*main model
*logit own_candLCMpre_sen i.ideo6pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
*somewhat liberals/conservatives
eststo clear
logit own_candLCMpre_sen i.ideo6pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo slib: margins 3.ideo6pre, dydx(own_incLCMpre_sen) post 
logit own_candLCMpre_sen i.ideo6pre##i.own_incLCMpre_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo scon: margins 5.ideo6pre, dydx(own_incLCMpre_sen) post
coefplot (slib, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(scon, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) yscale(range(0(.02).20)) ylabel(0(.02).20) ///
ytitle("Incumbency effect") title("Weak") legend(off) ///
graphregion(color(white)) name(figure2d, replace)
*liberals/conservatives
eststo clear
logit own_candLCMpre_sen i.ideo6pre##i.own_incLCMpre_sen $demo3  i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo lib: margins 2.ideo6pre, dydx(own_incLCMpre_sen) post 
logit own_candLCMpre_sen i.ideo6pre##i.own_incLCMpre_sen $demo3  i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo con: margins 6.ideo6pre, dydx(own_incLCMpre_sen) post
coefplot (lib, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(con, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) yscale(range(0(.02).20)) ylabel(0(.02).20) ///
ytitle("") title("Medium") legend(off) ///
graphregion(color(white)) name(figure2e, replace)
*very lib/con
eststo clear
logit own_candLCMpre_sen i.ideo6pre##i.own_incLCMpre_sen $demo3  i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo vlib: margins 1.ideo6pre, dydx(own_incLCMpre_sen) post 
logit own_candLCMpre_sen i.ideo6pre##i.own_incLCMpre_sen $demo3  i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo vcon: margins 7.ideo6pre, dydx(own_incLCMpre_sen) post
coefplot (vlib, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(vcon, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) yscale(range(0(.02).20)) ylabel(0(.02).20) ///
ytitle("") title("Strong") legend(off) ///
graphregion(color(white)) name(figure2f, replace)

graph combine figure2d figure2e figure2f, title("Senate") graphregion(color(white)) name(senate_comb)


*FINAL
graph combine house_comb senate_comb, graphregion(color(white)) name(figure1)





